package com.rjpacket.supernews.app.adapters;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import com.rjpacket.supernews.app.R;
import com.rjpacket.supernews.app.models.CategoryTitle;

import java.util.List;

/**
 * Created by aaa on 15-3-13.
 */
public class ChannelSelectCheckedAdapter extends RecyclerView.Adapter<ChannelSelectCheckedAdapter.ViewHolder> {
    private Context context;
    private List<CategoryTitle> data;
    private int layoutId;

    private View.OnClickListener listener;

    public ChannelSelectCheckedAdapter(Context context, List<CategoryTitle> data, int layoutId) {
        this.context = context;
        this.data = data;
        this.layoutId = layoutId;

        if (context != null && context instanceof View.OnClickListener) {
            listener = (View.OnClickListener) context;
        }
    }

    @Override
    public ChannelSelectCheckedAdapter.ViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
        View view = LayoutInflater.from(context).inflate(layoutId, viewGroup, false);
        if (listener != null) {
            view.setOnClickListener(listener);
        }
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(ChannelSelectCheckedAdapter.ViewHolder viewHolder, int i) {
        CategoryTitle title = data.get(i);
        viewHolder.textView.setText(title.getName());
    }

    @Override
    public int getItemCount() {
        return data.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder {
        private TextView textView;

        public ViewHolder(View itemView) {
            super(itemView);
            textView = (TextView) itemView.findViewById(R.id.select_text);
        }
    }
}
